package com.xinxin.blockchain.dao.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xinxin.blockchain.dao.IMemberDao;
import com.xinxin.blockchain.mapper.MemberMapperExt;
import com.xinxin.blockchain.model.Member;
import com.xinxin.blockchain.model.MemberExample;

import java.util.List;

/**
 * <p>
 * 会员表 服务实现类
 * </p>
 *
 * @author ys
 * @since 2021-05-19
 */
public class MemberDao extends ServiceImpl<MemberMapperExt, Member> implements IMemberDao {

    @Override
    public Member getMemberByMobile(String fullMobile) {
        Wrapper<Member> queryWrapper = new QueryWrapper<Member>().lambda()
                .eq(Member::getDataStatus, true)
                .eq(Member::getMobile, fullMobile);
        return baseMapper.selectOne(queryWrapper);
    }

    @Override
    public List<Member> listMember(String registerType, String order) {
        return baseMapper.listMember(registerType, order);
    }

    @Override
    public Member searchMember(String account) {
        MemberExample example = new MemberExample();
        example.createCriteria().andAccountEqualTo(account);

        List<Member> list = baseMapper.selectByExample(example);
        // List<Member> list = baseMapper.selectList(new QueryWrapper<Member>().lambda().eq(Member::getAccount, account));

        return list.isEmpty() ? null : list.get(0);
    }

    @Override
    public int insertSelective(Member record) {
        return baseMapper.insertSelective(record);
        // return baseMapper.insert(record);
    }
}
